
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fim" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>



<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/js/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/js/layui/layui.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.form.js"></script>
    <link href="${pageContext.request.contextPath}/css/coupon/coupon.css" rel="stylesheet" media="none" onload="this.media='all'">
</head>
<body>

<div class="nav">
    <div class="head-logo">
        <a href="" ></a>
    </div>
    <div class="head-nav">
        <ul>
            <li><a href="${pageContext.request.contextPath}/index" class="first-item">首页</a> </li>
            <li><a href="">手机端</a> </li>
            <c:if test="${empty loginCustomer}">
                <li><a href="${pageContext.request.contextPath}/users/login.jsp">成为房东</a> </li>
            </c:if>
            <c:if test="${!empty loginCustomer}">
                <li><a href="${pageContext.request.contextPath}/house_owner/houseadd.jsp">成为房东</a> </li>
            </c:if>
            <c:if test="${empty loginCustomer}">
                <li><a href="${pageContext.request.contextPath}/users/login.jsp">房源订单中心</a> </li>
            </c:if>
            <c:if test="${!empty loginCustomer}">
                <li><a href="${pageContext.request.contextPath}/index/order">房源订单中心</a> </li>
            </c:if>
            <c:if test="${empty loginCustomer}">
                <li><a href="${pageContext.request.contextPath}/users/login.jsp">个人中心</a> </li>
            </c:if>
            <c:if test="${!empty loginCustomer}">
                <li><a href="${pageContext.request.contextPath}/index/personalCenter">个人中心</a> </li>
            </c:if>
            <li><a href="">帮助</a> </li>
        </ul>
    </div>
    <div class="head-login">
        <c:if test="${empty loginCustomer}">
            <a href="${pageContext.request.contextPath}/users/login.jsp">
                <img class="login-logo" src="${pageContext.request.contextPath}/image/login-logo.svg"/>
                <span class="login-title">登录</span>
            </a>
            <a href="">
                <img class="regist-logo" src="${pageContext.request.contextPath}/image/regist-logo.svg" >
                <span class="login-title">注册</span>
            </a>
        </c:if>
        <c:if test="${!empty loginCustomer}">
            欢迎${loginCustomer.cusNickname}登录，<a href="${pageContext.request.contextPath}/logout">退出</a>
        </c:if>
    </div>
</div>
<div class="main">
    <div class="coupon-titel">
        <label>礼券中心</label>
        <div class="tishi"></div>
    </div>
    <div class="main_left">
        <div id="coupon-main" class="layui-tab">
            <ul id="coupon-topic" class="layui-tab-title ">
                <li class="layui-this" id="firstpage">可使用优惠券</li>
                <li class="twopage">过期优惠券</li>
                <li id="thirdpage">已使用优惠券</li>
                <li id="fourpage">兑换优惠券</li>

            </ul>
            <div class="layui-tab-content coupon-context">
                <div id="first-item" class="layui-tab-item layui-show">
                    <ul class="coupon_user"></ul>
                </div>
                <script>
                    var url = "${pageContext.request.contextPath}/coupon/coupon/0";
                    var data ={"cusId":${loginCustomer.cusId}}
                    $.get(
                        url,
                        data,
                        function (result1) {
                            console.log(result1.data.couponId);
                            console.log(JSON.stringify(result1));
                            var array1 = result1.data;
                            if (array1 !=null ){
                                for (var i=0;i<array1.length;i++){
                                    var couponEle = '<li class="coupon_info1">\n' +
                                        '                            <div class="coupon_first">\n' +
                                        '                                <div class="coupon_top">\n' +
                                        '                                    <div class="coupon_top_left">\n' +
                                        '                                        <span class="coupon_mark">￥</span>\n' +
                                        '                                        <span class="coupon_number">'+array1[i].couponPrice+'</span>\n' +
                                        '                                    </div>\n' +
                                        '                                    <div class="coupon_top_center">\n' +
                                        '                                        <span class="coupon_name">新用户专享超值券</span>\n' +
                                        '                                        <span class="coupon_rule">满￥'+array1[i].couponLimit+'可用，14天内有效</span>\n' +
                                        '                                        <span class="coupon_symbol">未使用</span>\n' +
                                        '                                    </div>\n' +
                                        '                                    <div class="coupon_date">\n' +
                                        '                                        <span>使用时间为</span>\n' +
                                        '                                        <span>'+array1[i].couponStartDate+'</span><br/>\n' +
                                        '                                        <span >到</span><br/>\n' +
                                        '                                        <span>'+array1[i].couponEndDate+'</span>\n' +
                                        '                                    </div>\n' +
                                        '                                    <div class="coupon_top_right">\n' +
                                        '                                        <a href="" class="coupon_use">立即使用</a>\n' +
                                        '                                        <a href="javascript:deleteCoupon('+array1[i].couponId+')" class="coupon_delete">删除</a>\n' +
                                        '                                    </div>\n' +
                                        '                                </div>\n' +
                                        '                                <div class="coupon_footer">\n' +
                                        '                                    <span>仅限预订带有「超值券」标签的房源</span>\n' +
                                        '                                </div>\n' +
                                        '                            </div>\n' +
                                        '                        </li>'
                                    $(".coupon_user").prepend(couponEle);
                                }
                            }

                        },
                        "json"
                    );
                </script>
                <div id="two-item" class="layui-tab-item">
                    <ul class="coupon_array_over">
                    </ul>
                </div>
                <script>
                    var url = "${pageContext.request.contextPath}/coupon/coupon/2";
                    var data ={"cusId":${loginCustomer.cusId}}
                    $.get(
                        url,
                        data,
                        function (result1) {
                            console.log(result1.data.couponId);
                            console.log(JSON.stringify(result1));
                            var array1 = result1.data;
                            if (array1 !=null ){
                                for (var i=0;i<array1.length;i++){
                                    var couponEle = '<li class="coupon_info1">\n' +
                                        '                            <div class="coupon_first">\n' +
                                        '                                <div class="coupon_top">\n' +
                                        '                                    <div class="coupon_top_left">\n' +
                                        '                                        <span class="coupon_mark">￥</span>\n' +
                                        '                                        <span class="coupon_number">'+array1[i].couponPrice+'</span>\n' +
                                        '                                    </div>\n' +
                                        '                                    <div class="coupon_top_center">\n' +
                                        '                                        <span class="coupon_name">新用户专享超值券</span>\n' +
                                        '                                        <span class="coupon_rule">满￥'+array1[i].couponLimit+'可用，14天内有效</span>\n' +
                                        '                                        <span class="coupon_symbol">已过期</span>\n' +
                                        '                                    </div>\n' +
                                        '                                    <div class="coupon_date">\n' +
                                        '                                        <span>使用时间为</span>\n' +
                                        '                                        <span>'+array1[i].couponStartDate+'</span><br/>\n' +
                                        '                                        <span >到</span><br/>\n' +
                                        '                                        <span>'+array1[i].couponEndDate+'</span>\n' +
                                        '                                    </div>\n' +
                                        '                                    <div class="coupon_top_right">\n' +
                                        '                                        <a href="" class="coupon_use">立即使用</a>\n' +
                                        '                                        <a href="javascript:deleteCoupon('+array1[i].couponId+')" class="coupon_delete">删除</a>\n' +
                                        '                                    </div>\n' +
                                        '                                </div>\n' +
                                        '                                <div class="coupon_footer">\n' +
                                        '                                    <span>仅限预订带有「超值券」标签的房源</span>\n' +
                                        '                                </div>\n' +
                                        '                            </div>\n' +
                                        '                        </li>'
                                    $(".coupon_array_over").prepend(couponEle);
                                }
                            }

                        },
                        "json"
                    );
                    function deleteCoupon(couponId) {
                        var url = "${pageContext.request.contextPath}/coupon/coupon/"+couponId;
                        $.ajax({
                            url,
                            type: "POST",
                            data:"_method=delete",
                            dataType: "json",
                            success(result){
                                console.log(result);
                                console.log(JSON.stringify(result));
                            }
                        });
                    }
                </script>
                <div id="third-item" class="layui-tab-item">
                  <ul class="coupon_array">
                  </ul>
                </div>
                <script>
                    //$("#thirdpage").click(function () {
                        var url="${pageContext.request.contextPath}/coupon/coupon/1";
                        var data={"cusId":${loginCustomer.cusId}}
                        $.get(
                            url,
                            data,
                            function (result) {
                                console.log(result);
                                console.log(JSON.stringify(result));
                                var array = result.data;
                                if (array !=null ){
                                    for (var i=0;i<array.length;i++){
                                        var couponEle = '<li class="coupon_info">\n' +
                                            '                            <div class="coupon_first">\n' +
                                            '                                <div class="coupon_top">\n' +
                                            '                                    <div class="coupon_top_left">\n' +
                                            '                                        <span class="coupon_mark">￥</span>\n' +
                                            '                                        <span class="coupon_number">'+array[i].couponPrice+'</span>\n' +
                                            '                                    </div>\n' +
                                            '                                    <div class="coupon_top_center">\n' +
                                            '                                        <span class="coupon_name">新用户专享超值券</span>\n' +
                                            '                                        <span class="coupon_rule">满￥'+array[i].couponLimit+'可用，14天内有效</span>\n' +
                                            '                                        <span class="coupon_symbol">已使用</span>\n' +
                                            '                                    </div>\n' +
                                            '                                    <div class="coupon_date">\n' +
                                            '                                        <span>使用时间为</span>\n' +
                                            '                                        <span>'+array[i].couponStartDate+'</span><br/>\n' +
                                            '                                        <span >到</span><br/>\n' +
                                            '                                        <span>'+array[i].couponEndDate+'</span>\n' +
                                            '                                    </div>\n' +
                                            '                                    <div class="coupon_top_right">\n' +
                                            '                                        <a href="" class="coupon_use">立即使用</a>\n' +
                                            '                                        <a href="javascript:deleteCoupon('+array[i].couponId +')" class="coupon_delete">删除</a>\n' +
                                            '                                    </div>\n' +
                                            '                                </div>\n' +
                                            '                                <div class="coupon_footer">\n' +
                                            '                                    <span>仅限预订带有「超值券」标签的房源</span>\n' +
                                            '                                </div>\n' +
                                            '                            </div>\n' +
                                            '                        </li>'
                                        $(".coupon_array").prepend(couponEle);
                                    }
                                }

                            },
                            "json"
                        );
                        function deleteCoupon(couId) {
                            var url = "${pageContext.request.contextPath}/coupon/coupon/"+couId;
                            $.ajax({
                                url,
                                type: "POST",
                                data:"_method=delete",
                                dataType: "json",
                                success(result){
                                    console.log(result);
                                    console.log(JSON.stringify(result));
                                }
                            });
                        }
                   // })
                </script>
                <div id="four-item" class="layui-tab-item">
                    <span class="save_msg"></span>
                    <span>积分数</span>
                    <span class="point">${pointServer.data.pointNumber}</span>
                    <form id="coupon_six" class="coupon_first" method="post">
                            <div class="coupon_top">
                                <div class="coupon_top_left">
                                    <span class="coupon_mark">￥</span>
                                    <span class="coupon_number1">70</span>
                                </div>
                                <div class="coupon_top_center">
                                    <span class="coupon_name">积分兑换劵</span>
                                    <span class="coupon_rule">满￥<span id="number1">700</span>可用，14天内有效</span>
                                </div>
                                <div class="coupon_top_right">
                                    <input type="button" value="兑换" id="coupon_use1">
                                </div>
                            </div>
                            <div class="coupon_footer">
                                <span>可预定任何的房源</span>
                            </div>
                        </form>
                    <form id="coupon_seven" class="coupon_first" method="post">
                            <div class="coupon_top">
                                <div class="coupon_top_left">
                                    <span class="coupon_mark">￥</span>
                                    <span id="coupon_number2">50</span>
                                </div>
                                <div class="coupon_top_center">
                                    <span class="coupon_name">新用户专享超值券</span>
                                    <span class="coupon_rule">满￥<span id="number2">500</span>可用，14天内有效</span>
                                </div>
                                <div class="coupon_top_right">
                                    <input type="button" value="兑换" id="coupon_use2">
                                </div>
                            </div>
                            <div class="coupon_footer">
                                <span>可预定任何的房源</span>
                            </div>
                        </form>
                    <form id="coupon_night" class="coupon_first" method="post">
                            <div class="coupon_top">
                                <div class="coupon_top_left">
                                    <span class="coupon_mark">￥</span>
                                    <span id="coupon_number3">40</span>
                                </div>
                                <div class="coupon_top_center">
                                    <span class="coupon_name">积分兑换劵</span>
                                    <span class="coupon_rule">满￥<span id="number3">400</span>可用，14天内有效</span>
                                </div>
                                <div class="coupon_top_right">
                                    <input type="button" value="兑换" id="coupon_use3">
                                </div>
                            </div>
                            <div class="coupon_footer">
                                <span>可预定任何的房源</span>
                            </div>
                        </form>
                    <form id="coupon_nine" class="coupon_first" method="post">
                            <div class="coupon_top">
                                <div class="coupon_top_left">
                                    <span class="coupon_mark">￥</span>
                                    <span id="coupon_number4">30</span>
                                </div>
                                <div class="coupon_top_center">
                                    <span class="coupon_name">积分兑换劵</span>
                                    <span class="coupon_rule">满￥<span id="number4">300</span>可用，14天内有效</span>
                                </div>
                                <div class="coupon_top_right">
                                    <input type="button" value="兑换" id="coupon_use4">
                                </div>
                            </div>
                            <div class="coupon_footer">
                                <span>可预定任何的房源</span>
                            </div>
                        </form>
                  <script>
                      $("#coupon_use1").click(function () {
                            console.log("->>>>>>>>>>>"+${pointServer.data.pointNumber})
                            var startDate1 = new Date;
                            var endDate1 = new Date;
                            var couponLimit = 700
                            var point = ${pointServer.data.pointNumber}
                            endDate1.setMonth(startDate1.getMonth()+1);
                            var Data = {"cusId":${loginCustomer.cusId},
                                "couponStartDate":startDate1,
                                "couponEndDate":endDate1,
                                "couponLimit":couponLimit,
                                "couponPrice":"70",
                                "couponStatus":"0"
                            };
                            if (point>=couponLimit){
                                var url1 = "${pageContext.request.contextPath}/coupon/coupon"
                                var dataType = "json";
                                $.post(
                                    url1,
                                    Data,
                                    function (result) {
                                        console.log(result);
                                        console.log(JSON.stringify(result));
                                    },
                                    dataType
                                )
                                var pointNumber =point-couponLimit;
                                var  data1={
                                    "pointNumber":pointNumber,
                                }
                                console.log(data1)
                                $.ajax({
                                    url:"${pageContext.request.contextPath}/coupon",
                                    data1,
                                    type:"POST",
                                    dataType:"json",
                                    cache : true,
                                    async : true,
                                    success:function (result) {
                                        console.log(result)
                                        if (result !=null){
                                            $(".point2").text(pointNumber);
                                            alert("兑换成功")
                                        }else {
                                            alert("兑换失败")
                                        }
                                    }
                                })
                                $(".tishi").text("兑换成功");
                            }else {
                                $(".tishi").text("积分不足，无法兑换此优惠券");
                            }
                      });
                      $("#coupon_use2").click(function () {
                          var startDate1 = new Date;
                          var endDate1 = new Date;
                          var couponLimit = 500
                          var point = ${pointServer.data.pointNumber}
                          endDate1.setMonth(startDate1.getMonth()+1);
                          var Data = {"cusId":${loginCustomer.cusId},
                              "couponStartDate":startDate1,
                              "couponEndDate":endDate1,
                              "couponLimit":couponLimit,
                              "couponPrice":"50",
                              "couponStatus":"0"
                          };
                          var Data1 = {
                              "pointId":${pointServer.data.pointId},
                              "pointNumber":point-couponLimit,
                              "vipId":${pointServer.data.vipId},
                              "pointStatus":${pointServer.data.pointStatus},
                          };
                          if (point>=couponLimit){
                              var url = "${pageContext.request.contextPath}/coupon/coupon"
                              var dataType = "json";
                              $.post(
                                  url,
                                  Data,
                                  function (result) {
                                      console.log(result);
                                      console.log(JSON.stringify(result));
                                      $(".point").text(result.data.pointNumber)
                                      // $("#first-item").text(result.reason);
                                  },
                                  dataType
                              )
                              var url1 = "${pageContext.request.contextPath}/coupon"
                              $(".tishi").text("兑换成功");
                          }else {
                              $(".tishi").text("积分不足，无法兑换此优惠券");
                          }
                      });
                      $("#coupon_use3").click(function () {
                          var startDate1 = new Date;
                          var endDate1 = new Date;
                          var couponLimit = 400
                          var point = ${pointServer.data.pointNumber}
                          endDate1.setMonth(startDate1.getMonth()+1);
                          var Data = {"cusId":${loginCustomer.cusId},
                              "couponStartDate":startDate1,
                              "couponEndDate":endDate1,
                              "couponLimit":couponLimit,
                              "couponPrice":"40",
                              "couponStatus":"0"
                          };
                          if (point>=couponLimit){
                              var url = "${pageContext.request.contextPath}/coupon/coupon"
                              var dataType = "json";
                              $.post(
                                  url,
                                  Data,
                                  function (result) {
                                      console.log(result);
                                      console.log(JSON.stringify(result));
                                      $(".tishi").text("兑换成功");
                                  },
                                  dataType
                              )
                          }else {
                              $(".tishi").text("积分不足，无法兑换此优惠券");
                          }

                      });
                      $("#coupon_use4").click(function () {
                          var startDate1 = new Date;
                          var endDate1 = new Date;
                          var couponLimit = 300
                          var point = ${pointServer.data.pointNumber}
                          endDate1.setMonth(startDate1.getMonth()+1);
                          var Data = {"cusId":${loginCustomer.cusId},
                              "couponStartDate":startDate1,
                              "couponEndDate":endDate1,
                              "couponLimit":couponLimit,
                              "couponPrice":"30",
                              "couponStatus":"0"
                          };
                          if (point>=couponLimit){
                              var url = "${pageContext.request.contextPath}/coupon/coupon"
                              var dataType = "json";
                              $.post(
                                  url,
                                  Data,
                                  function (result) {
                                      console.log(result);
                                      console.log(JSON.stringify(result));
                                      $(".tishi").text("兑换成功");
                                  },
                                  dataType

                              )
                          }else {
                              $(".tishi").text("积分不足，无法兑换此优惠券");
                          }

                      });
                    </script>
                </div>
            </div>
        </div>
    </div>
    <div class="main_right" >
        <div class="main_right_owe">
            <label>兑换优惠券规则如下</label>
            <ul>
                <li>满￥700 立减￥70，需要积分700</li>
                <li>满￥500 立减￥50，需要积分500</li>
                <li>满￥400 立减￥40，需要积分400</li>
                <li>满￥300 立减￥30，需要积分300</li>
            </ul>
        </div>
        <div class="main_right_tow">
            <label>使用规则</label>
            <p>优惠券满减额度仅适用于房费和清洁费，不适用服务费、税费或其他相关费用。<br/>
                优惠券不可用于已确认的预订。<br/>
                优惠券仅限单次预订使用，若订单因为任何原因取消或变更，用户所能得到的最高退款金额只限于实际支付的金额。<br/>
                若用户取消一笔使用了优惠券的预订，已经使用的优惠券则不再有效。
            </p>
        </div>
    </div>
</div>

</body>
</html>
